-
Notifications
You must be signed in to change notification settings - Fork 0
Mastermind #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Mastermind #98
Conversation
…indGame. Implemented code length, character correctness, and code repetition tests in MasterMind Test.
…as incorrect. Extended Code to four characters, which passes the Code Length and content tests.
…time issues and decouples content and length tests.
…ode Generation using Java's Random utility and the System Time. Verified that codes of 4 characters from a set of 10 characters are vanishingly unlikely to collide in a sample of 100.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runtime behavior test checks out fine (no change).
Regression tests check out fine (no change).
Checkstyle reports new errors in MasterMindGame.java.
A suggestion for handling the magic number "10" is to use the length
property of the VALID_CHARACTER
array.
PMD identified potential weaknesses in MasterMindGameTest.java.
The first isn't likely to be appropriate to this case. The second correctly identifies code that should be deleted from the file.
Checkstyle reports a minor error to be corrected in MasterMindGameTest.java.
* I was curious as to the odds of an overlap, and before spending ages | ||
* rerunning "ant test" to no avail, I checked via Wolfram Alpha. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If written in first person, a comment needs to also provide authorship.
// Commented below after ensuring code equality check is correct | ||
// printCodes(codes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented-out code.
|
||
// Commented below after ensuring code equality check is correct | ||
// printCodes(codes); | ||
assertEquals(count, codes.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An assertion failure message here would be welcome to better explain what was being tested.
private static void printCodes(final HashSet<String> in) { | ||
for (String i: in) { | ||
System.out.println(i); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As identified by static analysis tools, this method is never used and should be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses Issue #44 by implementing the generateCode() method to pseudo-randomly generate a four-character code composed of digits 0-9, and adds comprehensive tests in MasterMindGameTest.java.
- Implements generateCode() in MasterMindGame.java
- Adds unit tests ensuring code length, content, and uniqueness in MasterMindGameTest.java
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
MasterMindGameTest.java | Adds tests validating code properties and randomness |
MasterMindGame.java | Implements code generation with pseudo-random digits |
Random r = new Random(System.nanoTime()); | ||
StringBuilder out = new StringBuilder(); | ||
for (int i = 0; i < CODE_LENGTH; i++) { | ||
out.append(VALID_CHARACTER[r.nextInt(10)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider reusing a single Random instance rather than creating a new one on every call to generateCode() to reduce overhead and improve randomness consistency.
Random r = new Random(System.nanoTime()); | |
StringBuilder out = new StringBuilder(); | |
for (int i = 0; i < CODE_LENGTH; i++) { | |
out.append(VALID_CHARACTER[r.nextInt(10)]); | |
StringBuilder out = new StringBuilder(); | |
for (int i = 0; i < CODE_LENGTH; i++) { | |
out.append(VALID_CHARACTER[RANDOM.nextInt(10)]); |
Copilot uses AI. Check for mistakes.
Random r = new Random(System.nanoTime()); | ||
StringBuilder out = new StringBuilder(); | ||
for (int i = 0; i < CODE_LENGTH; i++) { | ||
out.append(VALID_CHARACTER[r.nextInt(10)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace the hard-coded literal 10 with VALID_CHARACTER.length for improved maintainability, ensuring that any changes to the valid character set are automatically reflected in generateCode().
out.append(VALID_CHARACTER[r.nextInt(10)]); | |
out.append(VALID_CHARACTER[r.nextInt(VALID_CHARACTER.length)]); |
Copilot uses AI. Check for mistakes.
Addresses #44
The
generateCode()
method psuedo-randomly generates a four character code from the set of digits 0-9.Requesting Review from two willing others in accordance with this comment on Issue #44